package cn.vidoetest.com.houdavideo;

import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.BackgroundColorSpan;
import android.text.style.ImageSpan;
import android.util.Log;
import android.view.View;

import com.bumptech.glide.Glide;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;

import cn.vidoetest.com.controler.HouDaControl;
import cn.vidoetest.com.controler.HouDaVideoPlayerManager;
import cn.vidoetest.com.danmu.BiliDanmukuParser;
import cn.vidoetest.com.videoplayer.HouDaVideo;
import master.flame.danmaku.controller.IDanmakuView;
import master.flame.danmaku.danmaku.loader.ILoader;
import master.flame.danmaku.danmaku.loader.IllegalDataException;
import master.flame.danmaku.danmaku.loader.android.DanmakuLoaderFactory;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.IDanmakus;
import master.flame.danmaku.danmaku.model.IDisplayer;
import master.flame.danmaku.danmaku.model.android.BaseCacheStuffer;
import master.flame.danmaku.danmaku.model.android.DanmakuContext;
import master.flame.danmaku.danmaku.model.android.Danmakus;
import master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer;
import master.flame.danmaku.danmaku.parser.BaseDanmakuParser;
import master.flame.danmaku.danmaku.parser.IDataSource;
import master.flame.danmaku.danmaku.util.IOUtils;
import master.flame.danmaku.ui.widget.DanmakuView;

public class MainActivity extends AppCompatActivity {

    private HouDaVideo mHouDaVideo;

    private float i = 0.0f;
    private HouDaControl mController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mHouDaVideo=(HouDaVideo) findViewById(R.id.houdavido);
        String videoUrl = "http://jzvd.nathen.cn/b201be3093814908bf987320361c5a73/2f6d913ea25941ffa78cc53a59025383-5287d2089db37e62345123a1be272f8b.mp4";
        mHouDaVideo.setUp(videoUrl, null);
        mController = new HouDaControl(this);
        mController.setTitle("办公室小野开番外了，居然在办公室开澡堂！老板还点赞？");
        mController.setLenght(98000);
        Glide.with(this)
                .load("http://tanzi27niu.cdsb.mobi/wps/wp-content/uploads/2017/05/2017-05-17_17-30-43.jpg")
                .placeholder(R.drawable.img_default)
                .crossFade()
                .into(mController.imageView());
        mHouDaVideo.setController(mController);

        //弹幕
        initDanMu();


    }

    private void initDanMu() {

    }

    @Override
    protected void onStop() {
        super.onStop();
        HouDaVideoPlayerManager.instance().releaseNiceVideoPlayer();
    }

    @Override
    public void onBackPressed() {
        if (HouDaVideoPlayerManager.instance().onBackPressd()) return;
        super.onBackPressed();
    }

    public void fastpaly(View view) {
        mHouDaVideo.setSpeed(2.0f);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mController.getDanMuView()!= null && mController.getDanMuView().isPrepared()) {
            mController.getDanMuView().pause();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mController.getDanMuView() != null && mController.getDanMuView().isPrepared() && mController.getDanMuView().isPaused()) {
            mController.getDanMuView().resume();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mController.getDanMuView() != null) {
            // dont forget release!
            mController.getDanMuView().release();
            mController.setDanMuView(null);
        }
    }




}
